﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Read.Api.Application.Command.Processiings_OneWay;
using Traceability_Management.Read.Api.Application.Command.SlaughtsWay_NextWay;
using Traceability_Management.Read.Api.Application.CommandHandler.Processiings_OneWay;

namespace Traceability_Management.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Processiings_OneWayAllController : ControllerBase
    {
        IMediator mediator;

        public Processiings_OneWayAllController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        [HttpPost]
        public async Task<ApiResult<int>> AddOneWayAll(Processiings_One Processiings_One)
        {
            try
            {
                AddOneWayCommand AddOneWayCommand = new AddOneWayCommand() 
                {
                    Processiings_One = Processiings_One
                };
                return await mediator.Send(AddOneWayCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<Processiings_One>> FirstNextSlaughts([FromQuery] FirstOneWayCommand FirstOneWayCommand)
        {
            try
            {
                return await mediator.Send(FirstOneWayCommand);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [HttpPost]
        public async Task<ApiResult<int>> UpdateNextSlaughts(Processiings_One Processiings_One)
        {
            try
            {
                UpdateOneWayCommand UpdateOneWayCommand = new UpdateOneWayCommand()
                {
                    Processiings_One = Processiings_One
                };
                return await mediator.Send(UpdateOneWayCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
